//
//  CardsChildTableViewController.m
//  WBBaseProject
//
//  Created by xiaozhi on 2018/3/23.
//  Copyright © 2018年 吴斌. All rights reserved.
//

#import "TicketChildTableViewController.h"

#define VH 40

@interface TicketChildTableViewController ()

@property(strong,nonatomic)NSMutableArray *dataArr;

@property(strong,nonatomic) UIView * headView;
@property(strong,nonatomic) UIView * footView;

@end

@implementation TicketChildTableViewController
- (NSMutableArray *)dataArr
{
    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}
- (UIView *)headView
{
    if (!_headView) {
        _headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, VH)];
        _headView.backgroundColor = [UIColor whiteColor];
        
        UILabel* la = [[UILabel alloc]init];
        la.text = @"2张可用";
        la.textColor = [UIColor lightGrayColor];
        la.font = WB_FontSize(15);
        [_headView addSubview:la];
        [la mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(10);
            make.bottom.top.equalTo(0);
            make.width.equalTo(100);
        }];
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.titleLabel.font = WB_FontSize(15);
        //让按钮文字居中
        //btn.contentEdgeInsets = UIEdgeInsetsMake(-10, 0, 0, 0);
        [btn setTitle:@" 使用规则" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        UIImage *image = [UIImage imageNamed:@"提示-(2)"];
        [btn setImage:image forState:UIControlStateNormal];
        btn.adjustsImageWhenHighlighted = NO;
        
        [btn addTarget:self action:@selector(showDetail:) forControlEvents:UIControlEventTouchUpInside];
        [_headView addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(-10);
            make.bottom.top.equalTo(0);
            make.width.equalTo(100);
        }];
    
    }
    return _headView;
}
- (void)showDetail:(UIButton *)btn
{
    if (self.showDetail) {
        self.showDetail();
    }
}
- (UIView *)footView
{
    if (!_footView) {
        _footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, VH)];
        _footView.backgroundColor = [UIColor whiteColor];
        
        UILabel* la = [[UILabel alloc]init];
        la.text = @"没有更多券了";
        la.textAlignment = NSTextAlignmentCenter;
        la.textColor = [UIColor lightGrayColor];
        la.font = WB_FontSize(15);
        [_footView addSubview:la];
        [la mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(10);
            make.bottom.top.equalTo(0);
        }];
    }
    return _footView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    [self.tableView registerNib:[UINib nibWithNibName:@"TicketTableViewCell" bundle:nil] forCellReuseIdentifier:@"TicketTableViewCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self initVC];
    
   // [self getData];
}
- (void)getData
{
//type类型：1：红包、2：抵用、代金券、3：投资体验金 4:加息券
    [XYHttpRequest dataRequestGetVirtualMoneyWithDic:@{@"custId":@"490ea1f9bdbd448ba0c7b39b6b331f95",@"type":@"1",@"pageNo":@"1",@"pageSize":@"10",@"signature":@"",} success:^(id responseObj) {
        
        NSLog(@"------%@",responseObj);
    } failure:^(NSError *error) {
        
    }];
}
- (void)initVC
{
    [self addNavBtn];
    
    if (self.type == expire) {
        self.title = @"失效券";
    }
}
- (void)addNavBtn{
    //返回按钮
    UIButton *btn = [Factory backButton:self];
    [btn addTarget:self action:@selector(clickBack:) forControlEvents:UIControlEventTouchUpInside];
    
//    UIButton *right = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
//    right.titleLabel.font = WB_FontSize(15);
//    [right setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [right setTitle:@"添加" forState:UIControlStateNormal];
//    [right addTarget:self action:@selector(toAdd) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:right];
//    self.navigationItem.rightBarButtonItem = item;
}
- (void)clickBack:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)toAdd
{
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TicketTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TicketTableViewCell"];
    
    cell.Type = self.type;
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 120;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (self.type == expire) {
        return 0;
    }
    return VH;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return self.headView;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return self.footView;
}


@end
